home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1994 / MacHack 1994.toast / MacHack™94 / Talks & Papers / Michael D. Crawford↵ / Word Services SDK 1.0.5 / Writeswell Jr. Source / TableCheck.c < prev    next >
Text File  |  1993-03-17  |  5KB  |  151 lines

  1. /* DoChecking.c
  2.  * Functions that actually do the calls to the Word Services servers.
  3.  * ©1992 Working Software, Inc.
  4.  * This source code is copyrighted.  Permission is granted to use the Word Services
  5.  * portion of the Writeswell Jr. source code in your own programs, but you 
  6.  * may not distribute the Writeswell Jr. word-processor code as a 
  7.  * commercial product.  If you modify the code, please do not call it 
  8.  * Writeswell Jr. (or Writeswell.)  This will ensure that people understand the 
  9.  * program and don’t have to deal with a number of different versions with 
  10.  * who-knows-what going on in the code.
  11.  * 
  12.  * Writeswell Jr. and Writeswell are trademarks of Working Software, Inc.
  13.  * 24 Sep 92 Mike Crawford
  14.  */
  15.  
  16. #include <AppleEvents.h>
  17. #include <AEObjects.h>
  18. #include <AEPackObject.h>
  19. #include <AERegistry.h>
  20. #include "TBConstants.h"
  21. #include "TBGlobals.h"
  22. #include "WordServices.h"
  23. #include "AppEvents.h"
  24. #include "ObWind.h"
  25. #include "Gripe.h"
  26. #include "Prefs.h"
  27. #include "TableCheck.h"
  28.  
  29. OSErr DoBatchTableCheck( AEAddressDesc *spellerAddrPtr )
  30. {
  31.     OSErr            err;
  32.     AEDesc            tableSpec;
  33.     AEDesc            textDescriptor;
  34.     AEDesc            textSpecifier;
  35.     AppleEvent        btchEvent;
  36.     AppleEvent        replyEvent;
  37.     WWJrPrefsHdl    prefHdl;
  38.     AEDescList        textSpecList;            /* 1.0d7 */
  39.     long            index;                    /* 1.0d7 */
  40.  
  41.     /* In this case we don't send the object specifiers for the text explicitly.
  42.      * Instead, we send a single object specifier for a table of object specifiers.
  43.      * The speller can then ask for them one at a time.
  44.      *
  45.      * In our particular case, the table is just the document window.  The elements of
  46.      * the table are the elements of typeObjectSpecifier within the window.
  47.      *
  48.      * There's just one element in our particular case.
  49.      *
  50.      * I'm not real sure about what the best way to do this is.  The way the protocol
  51.      * works, the table can be anything, within any container.  The table itself can
  52.      * have any type.  It just needs to have elements that are object specifiers.
  53.      */
  54.     
  55.  
  56.     /* We make an object specifier that refers to _our_own_ window
  57.      */
  58.  
  59.     err = BuildWindowSpecifier( &tableSpec, 1 );
  60.     if ( err ){
  61.         Gripe( "\pBuildWindowDescriptor failed" );
  62.         return err;
  63.     }
  64.  
  65.     /* Create the event to send to the speller */
  66.     
  67.     err = AECreateAppleEvent( kWordServicesClass,
  68.                                 kWSBatchCheckMe,
  69.                                 spellerAddrPtr,
  70.                                 kAutoGenerateReturnID,
  71.                                 kAnyTransactionID,
  72.                                 &btchEvent );
  73.     
  74.     if ( err ){
  75.         Gripe( "\pcreate btch event failed" );
  76.         return err;
  77.     }
  78.     err = AEDisposeDesc( spellerAddrPtr );
  79.     if ( err ){
  80.         Gripe( "\pAEDisposeDesc failed" );
  81.         return err;
  82.     }
  83.  
  84.  
  85.     /* Insert the table specifier as the direct object of the batch event */
  86.  
  87.     err = AEPutParamDesc( &btchEvent,
  88.                             keyDirectObject,
  89.                             &tableSpec );
  90.     if ( err ){
  91.         Gripe( "\pAEPutParamDesc failed to put direct object on batch event" );
  92.         return err;
  93.     }
  94.     err = AEDisposeDesc( &tableSpec );        /* 1.0d12 was textSpecifier... bad bug */
  95.     if ( err ){
  96.         Gripe( "\pAEDisposeDesc failed" );
  97.         return err;
  98.     }
  99.  
  100.     /* Send the event.  We await the reply, so that if there is a failure of some
  101.      * sort in the initial connection, we can alert the user right away.  The timeout
  102.      * value to use here should be as long as one would care to have a user wait for
  103.      * the completion of a menu command.  Since we expect that the speller is on a local
  104.      * machine in this case, and should be able to respond immediately, we just give
  105.      * a few seconds for the timeout.
  106.      *
  107.      * We should assign an idle proc to spin the cursor.  Even better would be a progress
  108.      * dialog that says "Contacting speller" or some such, with an animated display that
  109.      * shows the time elapsed relative to the total timeout, so the user will know how
  110.      * long she may have to wait
  111.      */
  112.  
  113. #define kFewSeconds 300
  114.     
  115.     err = AESend( &btchEvent,
  116.                     &replyEvent,
  117.                     kAEWaitReply + kAECanInteract + kAECanSwitchLayer,
  118.                     kAENormalPriority,
  119.                     kFewSeconds,
  120.                     (IdleProcPtr)NULL,
  121.                     (EventFilterProcPtr)NULL );
  122.     
  123.     if ( err ){
  124.         Gripe( "\psend btch event failed" );
  125.         return err;
  126.     }
  127.     err = AEDisposeDesc( &btchEvent );
  128.     if ( err ){
  129.         Gripe( "\pAEDisposeDesc failed" );
  130.         return err;
  131.     }
  132.     
  133.     /* MDC 1.1.1 */
  134.  
  135.     err = AEDisposeDesc( &replyEvent );
  136.     if ( err ){
  137.         Gripe( "\pAEDisposeDesc failed" );
  138.         return err;
  139.     }
  140.     
  141.     /* Now the event has been sent.  There is nothing more that we have to actually do
  142.      * on our own initiative to accomplish the spelling; we just sit back and respond
  143.      * to events.  In particular, we don't remember that spelling is taking place - once
  144.      * the spelling is done, we will just start seeing events from the user (mouse and
  145.      * key clicks and so on
  146.      */
  147.     
  148.     return noErr;
  149. }
  150.     
  151.